<script setup>
import { useRouter } from "vue-router"
import appStore from "@/stores"

const { switchTipStatus } = appStore.homeviewStore

const router = useRouter()
const linkTo = (path) => {
  router.push(path)
}
const unknownMethod = (methodName) => {
  switchTipStatus({ level: "warning", msg: `${methodName} 功能暂未开放` })
}

const props = defineProps({
  blog: {
    type: Object,
    required: true,
  },
})
</script>

<template>
  <div class="blog-card">
    <div v-if="props.blog.is_top" class="blog-top-ribbon">置顶</div>
    <div v-if="props.blog.blog_cover === ''" class="blog-image"></div>
    <img v-else class="blog-image" :src="props.blog.blog_cover" />
    <div class="blog-content">
      <div class="blog-header">
        <span>
          <span><i class="fas fa-user-circle"></i>{{ props.blog.author }}</span>
          <span
            v-for="(label, index) in props.blog.labels"
            class="blog-label"
            :key="index"
            @click="linkTo('/archive/' + label)"
            >#{{ label }}
          </span></span
        >
        <span><i class="far fa-calendar"></i>{{ props.blog.created_at.split("T")[0] }}</span>
      </div>
      <div>
        <h2
          class="blog-title"
          @click="linkTo('/blogs/reader/' + props.blog.id)"
          :title="props.blog.title">
          {{ props.blog.title }}
        </h2>
        <p class="blog-context">{{ props.blog.desc }}</p>
      </div>

      <div class="blog-stats">
        <span @click="linkTo('/blogs/reader/' + props.blog.id)"
          ><i class="fas fa-eye"></i>{{ props.blog.view_nums }}</span
        >
        <span @click="unknownMethod('点赞')"
          ><i class="fas fa-heart"></i>{{ props.blog.like_nums }}</span
        >
        <span @click="unknownMethod('评论')"><i class="fas fa-comment"></i>0</span>
      </div>
    </div>
  </div>
</template>

<style scoped>
.blog-card {
  background: var(--card-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-radius: var(--border-radius);
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: var(--transition);
  display: flex;
  height: 220px;
  position: relative;
}

.blog-card:hover {
  transform: translateY(-5px);
  box-shadow: var(--shadow);
  border-color: rgba(var(--primary-rgb), 0.5);
}

.blog-top-ribbon {
  position: absolute;
  left: -40px;
  top: 5px;
  z-index: 2;
  width: 120px;
  background: var(--primary-reverse);
  color: #fff;
  text-align: center;
  font-size: 15px;
  font-weight: bold;
  transform: rotate(-45deg);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  padding: 4px 0;
  letter-spacing: 2px;
  user-select: none;
}

.blog-image {
  width: 35%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 20px;
  font-weight: bold;
  position: relative;
  overflow: hidden;
}

.blog-image::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  opacity: 0.9;
}

.day-theme .blog-image::after,
.night-theme .blog-image::after {
  content: var(--title-gift);
  position: relative;
  z-index: 1;
  font-size: 48px;
  opacity: 0.8;
}

.blog-content {
  padding: 25px;
  width: 65%;
  display: flex;
  flex-direction: column;
}

.blog-header {
  display: flex;
  justify-content: space-between;
  margin: 5px 0;
}

.blog-header span {
  font-size: 16px;
  color: var(--text);
  margin: 0 16px 0 0;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}

.blog-header span i {
  margin-right: 5px;
  color: var(--secondary);
}

.blog-label {
  color: var(--gray);
  font-size: 16px;
  font-style: italic;
  transition: var(--transition);
}

.blog-label:hover {
  color: var(--primary);
  cursor: pointer;
}

.blog-title {
  color: var(--text);
  font-size: 25px;
  letter-spacing: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color 0.3s;
}

.blog-title:hover {
  color: var(--primary);
  cursor: pointer;
}

.blog-context {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
  line-height: 30px;
  font-size: 15px;
  color: var(--gray);
}

.blog-stats {
  display: flex;
  gap: 25px;
  color: var(--gray);
  font-size: 15px;
  margin-top: auto;
}

.blog-stats span {
  color: var(--secondary);
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  transition: var(--transition);
}

.blog-stats span:hover {
  color: var(--primary);
}

@media (max-width: 1100px) {
  .blog-card {
    height: auto;
    flex-direction: column;
  }

  .blog-image {
    width: 100%;
    height: 180px;
  }

  .blog-content {
    width: 100%;
  }
}

@media (max-width: 480px) {
  .blog-image {
    height: 150px;
  }
}
</style>
